﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedReg
{
    public partial class AcademicDegree : IEquatable<AcademicDegree>
    {
        public void ImportList(List<Classes.AcademicDegree> adList)
        {
            var mdb = new MedregDBDataContext();
            var ListAD = new List<AcademicDegree>();
            foreach (var ad in adList)
            {
                AcademicDegree ad1 = new AcademicDegree() { ID = ad.ID, Name = ad.Name };
                AcademicDegree query;

                if (mdb.AcademicDegree.LongCount() == 0)
                {
                    mdb.AcademicDegree.InsertOnSubmit(ad1);
                }
                else
                {
                    try
                    {
                        query = mdb.AcademicDegree.Single(l => l.ID == ad1.ID);
                        query.Name = ad1.Name;

                    }
                    catch (ArgumentNullException e)
                    {
                    }
                    catch (InvalidOperationException e)
                    {

                        if (!ListAD.Contains(ad1))
                        {
                            mdb.AcademicDegree.InsertOnSubmit(ad1);
                            ListAD.Add(ad1);
                        }
                    }
                }
            }
            mdb.SubmitChanges();
        }
        public bool Equals(AcademicDegree other)
        {
            var i = this.ID.Equals(other.ID);
            var j = this.Name.Equals(other.Name);
            if (i & j)
            {
                return true;
            }
            return false;
        }
    }
}
